﻿// JScript 文件
   
    var XmlValNew = null
    var XmlValOld = null 
    var vTicketNo = 0;
    var  vGdBh = "";
    var vIsSaved = false
    var vCount = 0;
   //-----------------------------------------------
   //----设置客户和业务信息
   //-----------------------------------------------
   
    function setTicketVal(vTicketVal)
    {
        try
        {
        　　//---------------取值--------------------------
            var XmlVal = CtnXML.getXmlDoc()
            XmlVal.loadXML(vTicketVal);
            
            var nodes = XmlVal.selectNodes('Items/Item');
            var CRM     = $XML(nodes[0].selectNodes("CRM")[0]);
            var WCSJ    = $XML(nodes[0].selectNodes("WCSJ")[0]);
            var JTYWLX  = $XML(nodes[0].selectNodes("JTYWLX")[0]);
            var YWMS    = $XML(nodes[0].selectNodes("YWMS")[0]);
            var DDBH    = $XML(nodes[0].selectNodes("DDBH")[0]);
            var NEWADD  = $XML(nodes[0].selectNodes("NEWADD")[0]);
            var OLDADD  = $XML(nodes[0].selectNodes("OLDADD")[0]);
            var NAME    = $XML(nodes[0].selectNodes("NAME")[0]);
            var CODE    = $XML(nodes[0].selectNodes("CODE")[0]);
            var KHLXR   = $XML(nodes[0].selectNodes("KHLXR")[0]);
            var KHLXDH  = $XML(nodes[0].selectNodes("KHLXDH")[0]);
            var KHJL    = $XML(nodes[0].selectNodes("KHJL")[0]);
            var KHJLDH  = $XML(nodes[0].selectNodes("KHJLDH")[0]);
            var KHDJ1   = $XML(nodes[0].selectNodes("KHDJ1")[0]);
            var KHDJ2   = $XML(nodes[0].selectNodes("KHDJ2")[0]); 
            var YWMC    = $XML(nodes[0].selectNodes("YWMC")[0]); 
            var YWDZ    = $XML(nodes[0].selectNodes("YWDZ")[0]);
            var KHBH    = $XML(nodes[0].selectNodes("KHBH")[0]);
            var KHXZDJ  = $XML(nodes[0].selectNodes("KHXZDJ")[0]);
            vTicketNo   = $XML(nodes[0].selectNodes("ID0")[0]);
            
            //--------------------设值----------------------------
         
            $("OldGrBm").value    = CRM;
            $("FinisTime").value  = WCSJ;
            $("YwLx").value       = YWMC;
            $("JtYwLx").value     = JTYWLX;
            $("YwXzMs").value     = YWMS;
            $("YwDz").value       = YWDZ;
            
            //------------------------------------------------
            
            $("DdBh").value      = DDBH;
            $("KhMc").value      = NAME;
            $("KhJlMc").value    = KHJL;
            $("KhJlDh").value    = KHJLDH;
            $("GbKh").value      = CODE;
            $("KhLxr").value     = KHLXR;
            $("KhLxDh").value     = KHLXDH; 
            $("NewAddress").value = NEWADD; 
            $("OldAddress").value = OLDADD;
            $("KhDj1").value     = KHDJ1; 
            $("KhDj2").value     = KHDJ2; 
            $("KHBH").value      = KHBH; 
            $("KHXZDJ").value    = KHXZDJ; 
                     
        }
        catch(e)
        {
        }
    }
    
    
   //-----------------------------------------------
   //----构造光路路由
   //-----------------------------------------------
   
    function ConstructAGrLyHtml(type)
    {
        var preXh = null
        var vQxSum = 1; 
        var straLy = "";
        var tmpNodes = (type == 0)? XmlValNew : XmlValOld;
        var nodes =  tmpNodes.selectNodes('items/item/ly');
        
         for(var i = 0; i < nodes.length; i++)
         {
            var tmpNode = nodes[i];
            var AdSb = "", BdSb = "";
            var Xh = $XML(tmpNode.selectNodes("xh")[0]);
            var AdBm = $XML(tmpNode.selectNodes("adbm")[0]);
            var AdMc = $XML(tmpNode.selectNodes("admc")[0]) || "";
            var Adkh = $XML(tmpNode.selectNodes("adkh")[0]) || "";
            var AdDz = $XML(tmpNode.selectNodes("addz")[0]) || "";
            var AdGl = $XML(tmpNode.selectNodes("adglmc")[0])|| "";
            var AGQx = $XML(tmpNode.selectNodes("adglqx")[0])|| "";
            var BdBm = $XML(tmpNode.selectNodes("bdbm")[0]);
            var BdMc = $XML(tmpNode.selectNodes("bdmc")[0]) || "";
            var Bdkh = $XML(tmpNode.selectNodes("bdkh")[0]) || "";
            var BdDz = $XML(tmpNode.selectNodes("bddz")[0]) || "";
            var BdGl = $XML(tmpNode.selectNodes("bdglmc")[0]) || "";
            var BGQx = $XML(tmpNode.selectNodes("bdglqx")[0]) || "";
            if(AdGl.length > 0){AdGl += "(" + AGQx + "芯)";}
            if(BdGl.length > 0){BdGl += "(" + BGQx + "芯)";}
            
            if(i == 0)
            {
                if(nodes.length > 1)
                {
                   if(Xh == $XML(nodes[1].selectNodes("xh")[0]))
                   {
                       vQxSum = 2
                   }
                }
            }
            
            if(vQxSum == 1)
            {
               AdSb = AdBm + "(" + AdMc + ")";
               BdSb = BdBm + "(" + BdMc + ")"; 
            }
            else
            {
               if(preXh == Xh)
               {
                   AdSb = AdMc
                   BdSb = BdMc
                   Xh = ""
               }  
               else
               {
                   AdSb = AdBm
                   BdSb = BdBm
               }   
            }
            var tmpAdzBm = (Adkh == "" || Adkh == "空")?AdDz: (Adkh + "/" + AdDz);
            var tmpBdzBm = (Bdkh == "" || Bdkh == "空")?BdDz: (Bdkh + "/" + BdDz);
            straLy += "<tr width=100%>"
                  + "<td>" + Xh + "</td>"
                  + "<td>" + AdSb + "</td>"
                  + "<td>" + tmpAdzBm + "</td>"
                  + "<td>" + AdGl + "</td>"
                  + "<td>" + BdSb + "</td>"
                  + "<td>" + tmpBdzBm + "</td>"
                  + "<td>" + BdGl + "</td>"
                  + "</tr>";
                  
            preXh = Xh;
         }
        if(nodes.length > 10)
        {
           vCount = 6
        }
        if(nodes.length > 16)
        {
           vCount = 12
        }  
         
         return straLy
    }
    
   //-----------------------------------------------
   //----构造光路路由
   //-----------------------------------------------
    
                  
    function ConstructGrLyHtml()
    {
       var vnodes00 =  XmlValNew.selectNodes('items/item/ly');
       var vnodes01 =  XmlValOld.selectNodes('items/item/ly'); 
       
       var vtrCount =  vnodes00.length + vnodes01.length + 3;
       
       var strLy = "<table width=100% class='STable' border=1 cellpadding=0; cellspacing=0>"
            + "<tr width=100%>"
            + "      <td style='width: 22px' rowspan='" + vtrCount + "' align=center>"
            + "          <font color=red><strong>路由信息</strong></font></td>";
         if(parseInt(vIsTransferCfg) == 1)
         {
             strLy += "<td colspan=7 style='background:Orange;'><strong>装机路由</strong></td></tr><tr width=100%>";
         }
          strLy += "    <td style='background-color: #99cc99;'><strong>序号</strong></td>"
             + "     <td style='background-color: #99cc99;'><strong>A端设备</strong></td>"
             + "     <td style='background-color: #99cc99;'><strong>A端端子</strong></td>"
             + "     <td style='background-color: #99cc99;'><strong>A端光缆</strong></td>"
             + "     <td style='background-color: #99cc99;'><strong>B端设备</strong></td>"
             + "     <td style='background-color: #99cc99;'><strong>B端端子</strong></td>"
             + "     <td style='background-color: #99cc99;'><strong>B端光缆</strong></td>"
             + "     </tr>";
         strLy += ConstructAGrLyHtml(0)
         if(parseInt(vIsTransferCfg) == 1)
         {
             strLy += "<tr width=100%><td colspan=7 style='background:Orange;'><strong>拆机路由</strong></td></tr>";
             strLy += ConstructAGrLyHtml(1)
         }
         strLy += "</table>"
         var vData = document.getElementById("TextLy")
         vData.innerHTML = strLy
    }
    
    //-----------------------------------------------
   //----构造光路路由
   //-----------------------------------------------
   
    function setGrLyVal(vGrLyVal)
    {
       var vsplit = vGrLyVal.split('??')
       XmlValNew = CtnXML.getXmlDoc()
       XmlValOld = CtnXML.getXmlDoc() 
       if(vsplit.length == 2)
       {
            XmlValNew.loadXML(vsplit[0]);
            XmlValOld.loadXML(vsplit[1]);
            ConstructGrLyHtml() 
       }  
       else
       {
            XmlValNew.loadXML(vGrLyVal);
            ConstructGrLyHtml() 
       }    
    }
    
    //-----------------------------------------------
    //----设置操作人
    //-----------------------------------------------
   
    function setLoginName(vLoginName)
    {
        document.getElementById("SjZzR").value = vLoginName
    }
    
    //-----------------------------------------------
    //----填充工单信息
    //-----------------------------------------------
    
    
    function DispTicketPrintInfo(xml)
    {
       if(xml)
       { 
           vsplit = xml.split('|||')
            
           if(vsplit.length > 2)
           {
              var  vTicketVal = vsplit[0]
              var  vGrLyVal   = vsplit[1]
              var  vLoginName = vsplit[2]
              var  vGrMc      = vsplit[3]
              vGdBh           = vsplit[4]
              vIsTransferCfg  = parseInt(vsplit[5])
              
              setTicketVal(vTicketVal)
              setGrLyVal(vGrLyVal)
              setLoginName(vLoginName);
              
              setGrTitle(vGrMc)
              setGdTitle(vGdBh)
             
           }   
           DelGr();
       }     
    }
    
    
  function setGrTitle(vGrMc)
  {
     var vGr = (vGrMc == "")? vGrBm : (vGrBm + "(" + vGrMc +")")
     vGr += " 一览表"
     document.getElementById("hTitleGr").innerHTML = "光路：<font color=blue>" + vGr + "</font>";
  }
  
  
  
   function setGdTitle(vGdBh)
   {
      document.getElementById("hTitleDd").innerHTML = "调度单编号：<font color=blue>" + vGdBh + "</font>";
   }  

	//-------------------------------------------------------------------------
	
    //打印
    function OnPrint()
    {
       bdhtml=window.document.body.innerHTML; 
       sprnstr="<!--startprint-->"; 
       eprnstr="<!--endprint-->"; 
       prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17); 
       prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr)); 
       window.document.body.innerHTML=prnhtml; 
       window.print()
      
       window.document.body.innerHTML=bdhtml;  
       
    }
    //另存为
    function executeCommand()
    {  
        var myCommand = document.execCommand("SaveAs", true, "FileName");  
    }
    
  
    
    //-------------------------------------------------------------
    
//报表部分

    function getHostName()
    {
       var vSp =  location.href.split('/');
       hostname = vSp[0] +"/"+ vSp[1] +"/"+ vSp[2] +"/"+ vSp[3];
       return hostname 
    }

    function CopyModel()
    {
        hostname = getHostName()
        var path = hostname + "/Template/ModelTicket.xls"
        if(vCount == 6)
        {
            path = hostname + "/Template/ModelTicket01.xls"
        }
        if(vCount == 12)
        {
            path = hostname + "/Template/ModelTicket02.xls"
        }
        if(parseInt(vIsTransferCfg) == 1)
        {
           path = hostname + "/Template/ModelDouTicket.xls"
            if(vCount == 6)
            {
                path = hostname + "/Template/ModelDouTicket01.xls"
            }
            if(vCount == 12)
            {
                path = hostname + "/Template/ModelDouTicket02.xls"
            }
        }
        
        
        var objExcel = new ActiveXObject("Excel.Application");
        var objBook2 = objExcel.Workbooks.Add();
        var objSheet2 = objBook2.Worksheets(1);
        var objBook1 = objExcel.Workbooks.Open(path);
        var count1  = objBook1.Worksheets.count;
        var count2  = objBook2.Worksheets.count;
        var objSheet1 = objBook1.ActiveSheet;
        var Activeindex = 1;   //当前活动的sheet
        var arrName = new Array();
        
        for (var i = 1; i <=count1  ;i++ )
        {
	        if (objSheet1 == objBook1.Worksheets(i))
	        {
		        Activeindex = i;
		        break;
	        }
        }
        
        //增加新的sheet
        for (var i = 1; i <=count1  ;i++ )
        {
	        objBook1.Worksheets(i).Activate();
	        objBook1.Worksheets(i).Select(true);
	        objBook1.Worksheets(i).copy(objSheet2, null);
	        arrName.push(objBook1.Worksheets(i).Name);
        }
        // 删除老的sheet
        for (var i = 1; i <= count2  ;  i++)
        {
	        objBook2.Worksheets("sheet" + i).Delete();
        }
        //copy sheet 名 
        for (var i = 1; i <=count1  ;i++ )
        {
	        objBook2.WorkSheets(i).Name = arrName[i-1];
        }
        
        objBook2.Worksheets(Activeindex).Activate();
        objBook1.close(false);
        xlExcel = objExcel
        return objBook2.Worksheets(Activeindex)
    }
    
    var xlsheet = ""
    var xlExcel = ""
    function setExcelValue()
    {
        try
        {
            
            xlsheet = CopyModel();
            setYwInfo();
            setYhInfo();
            setLyInfo();
            setBzInfo();
            setGrInfo();
            setGdInfo();
                        
            
        }
        catch(e)
        {
            alert("请启用ActiveX的运行权限后重起系统!(工具—>Internet选项－>安全－>自定义级别－>启用“没有标识为安全的ActiveX控件进行初始化和脚本运行)");
        }
        finally
        {
            xlExcel.UserControl = true;
            xlExcel.Visible = true;
        }
    }
    
    //删除光路 
    
    function DelGr()
    {
        if(parseInt(IDelGr) != 0)
        {
            IDelGr = DelGr
            var serverUrl = "_method=DelGr&GrBm="+vGrBm+"&GrType="+m_GrType;
            
             alert(top.CtnTrans.getText("/main.ashx?", "post", serverUrl))
        }
    }

    function setYwInfo()
    {
        //3,4  3,7  3,10
        //4 ,5 ,6
        //4 ,8 ,11
        //OldGrBm  YwDz  KdRq  FinisTime  YwLx  JtYwLx  YwXzMs 
        var RowPos0 = 4,RowPos1 = 5,RowPos2 = 6;
        xlsheet.Cells(RowPos0,4).value = document.getElementById("OldGrBm").value;
        xlsheet.Cells(RowPos0,8).value = document.getElementById("YwDz").value;
        xlsheet.Cells(RowPos0,11).value = document.getElementById("KdRq").value;
        xlsheet.Cells(RowPos1,4).value = document.getElementById("FinisTime").value;
        xlsheet.Cells(RowPos1,8).value = document.getElementById("YwLx").value;
        xlsheet.Cells(RowPos1,11).value = document.getElementById("JtYwLx").value;
        xlsheet.Cells(RowPos2,4).value = document.getElementById("YwXzMs").value;
    }
    
    function setYhInfo()
    {
        //7,4  7,8  7,11                  DdBh    KhMc      
        //8,4  8,8  8,11                  GbKh    KhLxr   KhLxDh      
        //9,4  9,8  9,11                  KHBH    KhJlDh  KhJlMc  
        //10,4 10,8 10,11                 KHLX    FWDJ    WHDJ
        //11,4                            NewAddress   
        //12,4                            OldAddress
        
        var RowPos0 = 7,RowPos01 = 8,RowPos1 = 9,RowPos2 = 10,RowPos3 = 11,RowPos4 = 12;
        
        xlsheet.Cells(RowPos0,4).value = document.getElementById("DdBh").value;
        xlsheet.Cells(RowPos0,8).value = document.getElementById("KhMc").value;

        
        xlsheet.Cells(RowPos01,4).value = document.getElementById("GbKh").value;
        xlsheet.Cells(RowPos01,8).value = document.getElementById("KhLxr").value;
        xlsheet.Cells(RowPos01,11).value = document.getElementById("KhLxDh").value;
        
        xlsheet.Cells(RowPos1,4).value = document.getElementById("KHBH").value;
        xlsheet.Cells(RowPos1,8).value = document.getElementById("KhJlMc").value;
        xlsheet.Cells(RowPos1,11).value = document.getElementById("KhJlDh").value;

        
        xlsheet.Cells(RowPos2,4).value = document.getElementById("KhDj1").value; 
        xlsheet.Cells(RowPos2,8).value = document.getElementById("KhDj2").value; 
        xlsheet.Cells(RowPos2,11).value = document.getElementById("KHXZDJ").value;
        
        xlsheet.Cells(RowPos3,4).value = document.getElementById("NewAddress").value; 
        
        if(parseInt(vIsTransferCfg) == 1)
        {
           xlsheet.Cells(RowPos4,4).value = document.getElementById("OldAddress").value;  
        }
    }
    
    
    function setBzInfo()
    {
        //24,4 24,8   SjZzR  BLxRdh
        //25,4 25,8   SgRXm  SgWcSj
        
         var RowPos0 = 25 + vCount,RowPos1 = 26 + vCount; 
         if(parseInt(vIsTransferCfg) == 1)
         {
             RowPos0 = 39 + vCount*2;
             RowPos1 = 40 + vCount*2;
         }
         
         xlsheet.Cells(RowPos0 - 2,2).value = document.getElementById("BzInfo").value;
         xlsheet.Cells(RowPos0,4).value = document.getElementById("SjZzR").value;
         xlsheet.Cells(RowPos0,8).value = document.getElementById("BLxRdh").value;
         xlsheet.Cells(RowPos1,4).value = document.getElementById("SgRXm").value;
         xlsheet.Cells(RowPos1,8).value = document.getElementById("SgWcSj").value;
    }
    
    //复制路由信息到excel
    
    
    function setLyInfo()
    {
        if(XmlValNew == null && XmlValOld == null)
        {
            return;
        }
        LyRowPos = 13;
        SetALyInfo(0);
        if(parseInt(vIsTransferCfg) == 1)
        {
           LyRowPos = 27 + RowAddVal + vCount;
           SetALyInfo(1);
        }
    }
    var LyRowPos = 13;
    var RowAddVal = 0;
    function SetALyInfo(vtype)
    {
        var preXh = null
        var vQxSum = 1; 
        var str = ""
        var tmpNodes = (vtype == 0)? XmlValNew : XmlValOld;
        var nodes =  tmpNodes.selectNodes('items/item/ly');
        
        if(parseInt(vIsTransferCfg) == 1 && vtype == 0)
        {
           LyRowPos = 15;
        }
         for(var i = 0; i < nodes.length; i++)
         {
            var tmpNode = nodes[i];
            var AdSb = "", BdSb = "";
            var Xh = $XML(tmpNode.selectNodes("xh")[0]);
            var AdBm = $XML(tmpNode.selectNodes("adbm")[0]);
            var AdMc = $XML(tmpNode.selectNodes("admc")[0]) || "";
            var Adkh = $XML(tmpNode.selectNodes("adkh")[0]) || "";
            var AdDz = $XML(tmpNode.selectNodes("addz")[0]) || "";
            var AdGl = $XML(tmpNode.selectNodes("adglmc")[0])|| "";
            var AGQx = $XML(tmpNode.selectNodes("adglqx")[0])|| "";
            var BdBm = $XML(tmpNode.selectNodes("bdbm")[0]);
            var BdMc = $XML(tmpNode.selectNodes("bdmc")[0]) || "";
            var Bdkh = $XML(tmpNode.selectNodes("bdkh")[0]) || "";
            var BdDz = $XML(tmpNode.selectNodes("bddz")[0]) || "";
            var BdGl = $XML(tmpNode.selectNodes("bdglmc")[0]) || "";
            var BGQx = $XML(tmpNode.selectNodes("bdglqx")[0]) || "";
            if(AdGl.length > 0){AdGl += "(" + AGQx + "芯)";}
            if(BdGl.length > 0){BdGl += "(" + BGQx + "芯)";}
            
            if(i == 0)
            {
                if(nodes.length > 1)
                {
                   if(Xh == $XML(nodes[1].selectNodes("xh")[0]))
                   {
                       vQxSum = 2
                   }
                }
            }
            
            if(vQxSum == 1)
            {
               AdSb = AdBm + "(" + AdMc + ")";
               BdSb = BdBm + "(" + BdMc + ")"; 
            }
            else
            {
               if(preXh == Xh)
               {
                   AdSb = AdMc
                   BdSb = BdMc
               }  
               else
               {
                   AdSb = AdBm
                   BdSb = BdBm
               }   
            }
            if(vQxSum * Xh > 22)
            {
                insertRow();
            }
            var tmpAdzBm = (Adkh == "" || Adkh == "空")?AdDz: (Adkh + "/" + AdDz);
            var tmpBdzBm = (Bdkh == "" || Bdkh == "空")?BdDz: (Bdkh + "/" + BdDz);
            if(preXh != Xh)
            {
               xlsheet.Cells(LyRowPos,2).value  = Xh;
            }
            xlsheet.Cells(LyRowPos,3).value  = AdSb;
            xlsheet.Cells(LyRowPos,5).value  = tmpAdzBm;
            xlsheet.Cells(LyRowPos,6).value  = AdGl;
            xlsheet.Cells(LyRowPos,8).value  = BdSb;
            xlsheet.Cells(LyRowPos,9).value  = tmpBdzBm;
            xlsheet.Cells(LyRowPos,10).value = BdGl;
            LyRowPos++;
            preXh = Xh;
         }
    }
    
    function setGrInfo()
    {
        var vData = document.getElementById("hTitleGr")
        var setValue ="光路:" + vData.childNodes[1].innerHTML;
        
        xlsheet.Cells(3,1).value = setValue
    }
    function setGdInfo()
    {
        var vData = document.getElementById("hTitleDd")
        var setValue ="调度单编号:" + vData.childNodes[1].innerHTML;
        
        xlsheet.Cells(2,1).value = setValue
    }
    
    //-----------------------------------------------
    //----当路由段数大于预留的行数时，向表中插入一行
    //-----------------------------------------------
    
    function insertRow()
    {
        //LyRowPos
        var pos = "B" + LyRowPos;
        
        xlsheet.Range(pos).Copy();//复制单元内容 
        xlsheet.Rows(LyRowPos).InsertRows(1);//从前位置插入指定行数
        xlsheet.Range(pos).Paste(); 
        
        
        RowAddVal++;
    }
   